<html>
  <head>
    <title></title>
  </head>
  <body>
    <script>
      var error = 0;
      var current_test = 0;

      function runNextTest() {
        test_list[current_test++]();
      }

      window.onerror = function() {
        error++;
        endTest();
      };

      function endTest() {
        document.title = error ? "Fail" : "Pass";
      }

      function echoStuff(stuff) {
        return function() {
          echo.echo(stuff, function(msg) {
            // Convenient way of comparing arrays.
            if (JSON.stringify(stuff) !== JSON.stringify(msg))
              error++;

            runNextTest();
          });
        };
      };

      var test_list = [
        echoStuff("Foobar"),
        echoStuff(12345),
        echoStuff([1, 2, 3, 4, 5]),
        echoStuff(["1", 2, "3", [4, 5]]),
        // Dictionary properties should be alpha sorted for testing,
        // because that's how JSON.stringify() will parse them.
        echoStuff({bar: "abc", foo: [ "test", 456], xyz: 123}),
        endTest
      ];

      runNextTest()
    </script>
  </body>
</html>
